package com.xdh.zzqh.utils
import com.xdh.zzqh.store.SqliteConn
import com.xdh.zzqh.ui.view.Order
import kotlinx.coroutines.CompletableDeferred


private var initFlag = false
private val initFuture = CompletableDeferred<Boolean>()

fun initAll() {
    if (initFlag) {
        return
    }
    initFlag = true
    runOnUi { initImpl() }
    initFuture.complete(true)
}

suspend fun waitInit() {
    initFuture.await()
}

private const val INDEX_TYPE = 0 // 类型
private const val INDEX_STYLE = 1 // 款式
private const val INDEX_SPEC = 2 // 规格
private const val INDEX_DIR = 3 // 开向
private const val INDEX_HANDS = 4 // 拉手
private const val INDEX_COLOR = 5 // 颜色
private const val INDEX_LEFT = 6
private const val INDEX_RIGHT = 7
private const val INDEX_PRICE = 8

private suspend fun initImpl() {

    SqliteConn.init()
}


class OrderInfo(
    val order: ArrayList<Order>,
    var name: String,
    var date: String
)

val globalOrderInfo = OrderInfo(arrayListOf(), "", "")


fun remarkSplitLine(remark: String): String {
    if (remark.length > 5) {
        val list = remark.chunked(5);
        val sb = StringBuilder()
        for (i in list.indices) {
            val item = list[i]
            sb.append(item)
            if (i != (list.size - 1)) {
                sb.append("\r\n")
            }
        }
        return sb.toString()
    }
    return remark
}



